<?php

class m120428_080453_create_auth extends CDbMigration {

	public function safeUp() {
		$auth = array(
			'name'=>'varchar(64) not null',
			'type'=>'integer not null',
			'description'=>'text',
			'bizrule'=>'text',
			'data'=>'text',
			'PRIMARY KEY (`name`)'
		);
		$this->createTable('auths', $auth);

		$auth_child = array(
			'parent'=>'varchar(64) not null',
			'child'=>'varchar(64) not null',
			'PRIMARY KEY (`parent`, `child`)'
		);
		$this->createTable('auth_childs', $auth_child);
//		$name = 'fk_auth_childs_parent_auths_name';
//		$table = 'auth_childs';
//		$this->addForeignKey(
//			$name, $table, 'parent', 'auths', 'name', 'cascade', 'cascade'
//		);
//		$name = 'fk_auth_childs_child_auths_name';
//		$this->addForeignKey(
//			$name, $table, 'child', 'auths', 'name', 'cascade', 'cascade'
//		);

		$auth_assignment = array(
			'itemname'=>'varchar(64) not null',
			'userid'=>'varchar(64) not null',
			'bizrule'=>'text',
			'data'=>'text',
			'PRIMARY KEY (`itemname`, `userid`)'
		);
		$this->createTable('auth_assignments', $auth_assignment);
//		$name = 'fk_auth_assignments_itemname_auths_name';
//		$table = 'auth_assignments';
//		$this->addForeignKey(
//			$name, $table, 'parent', 'auths', 'name', 'cascade', 'cascade'
//		);
	}

	public function safeDown() {
		$this->dropTable('auth_assignments');
		$this->dropTable('auth_childs');
		$this->dropTable('auths');
	}

}